using System;
using System.Runtime.Serialization;

namespace PDO.DataPersistence.Core
{
    [global::System.Serializable]
    public class InvalidFieldException : DataObjectsBaseException
    {
        public enum FieldExceptionReasons
        {
            FieldTooLong = 0,
            FieldTooShort = 1
        }

        public InvalidFieldException() : base() { }
        public InvalidFieldException(string message) : base(message) { }
        public InvalidFieldException(string message, Exception inner) : base(message, inner) { }

        public InvalidFieldException(string fieldName, string fieldValue, FieldExceptionReasons reason, int min, int max)
            : base(reason == FieldExceptionReasons.FieldTooLong ?
            (fieldName + " is too long. The field is " + fieldValue.Length.ToString(System.Globalization.CultureInfo.InvariantCulture) +
            " letters but only " + max.ToString(System.Globalization.CultureInfo.InvariantCulture) + " is allowed") :
            (fieldName + " is too short. The field is " + fieldValue.Length.ToString(System.Globalization.CultureInfo.InvariantCulture) +
            " letters but minimum is " + min.ToString(System.Globalization.CultureInfo.InvariantCulture))) { }

        protected InvalidFieldException(SerializationInfo info, StreamingContext context)
            : base(info, context) { }

    }
}
